$(function(){
	
	var status=$("#status").val();
	$('#wytel').live('click', function(event) {
	   if(status!='已认证'){
		 $("#textmsg").text('亲，您还未身份认证哦!');
		 $('#modal-alert').modal({
			 relatedTarget: this,
		 });
		 event.preventDefault();  
		 return;
		 
	  }
	   
	   
	
	});
	
	
	init();
    
    
    $("#year").change(function(){
    	init();
    });
    
     $("#month").change(function(){
    	init();
    });
    
    
    
    //检测平台
    var ua = window.navigator.userAgent.toLowerCase();
	if (ua.match(/MicroMessenger/i) == 'micromessenger') {
		//微信
		var option="<option value='微信支付'>微信支付</option>";
		   // option+="<option value='支付宝(手机版)'>支付宝支付</option>";
		
		$("#payType").append(option);
	
	} else {
		//判断是PC还是手机

		var system = {
			win: false,
			mac: false,
			xll: false
		};
		//检测平台
		var p = navigator.platform;
		system.win = p.indexOf("Win") == 0;
		system.mac = p.indexOf("Mac") == 0;
		system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
		//console.log(system);
		if (system.win || system.mac || system.xll) {
			//电脑
		    var  option="<option value='支付宝(电脑版)'>支付宝支付</option>";
			$("#payType").append(option);

		} else {
			var option="<option value='微信支付'>微信支付</option>";
		      // option+="<option value='支付宝(手机版)'>支付宝支付</option>";
		
		    $("#payType").append(option);
			
			
		}
	}
	
	
});


//初始化物业账单数据
function init(){
	
	var year=$("#year").val();
	var month=$("#month").val();
	
	var yearmonth="";
	
	if(year!==''&&month!==''){
		yearmonth=year+'-'+month;
	}
	
	if(year==''||month==''){
		$("#date_text").text("全部账单");
	}else{
		$("#date_text").text(yearmonth);
	}
	

	
	$.get('/getpropertybill',{'yearmonth':yearmonth},function(result){
		
		
		var list="";
		var yearmonth="";
		var resultT = result;
		if(result.length>0){
			for(var i in result){
				
				if(result[i].yearmonth!=yearmonth){
					list +='<div class="am-u-sm-12" style="background:#efefef;border-radius:5px;padding:2px;color:red;">';
					list+=result[i].yearmonth;
					list+='</div>';
					for(var j in resultT){
						if(result[i].yearmonth==resultT[j].yearmonth){
							list +='<div class="am-u-sm-12" style="padding:8px;">';
						
							list+='<div class="am-u-sm-4" style="padding:0px;">';
							list+=result[j].name;
							list+='</div>';
							
							list+='<div class="am-u-sm-4" style="padding:0px;">';
							list+='￥'+result[j].qsaccount;
							list+='</div>';
							
							list+='<div class="am-u-sm-4" style="padding:0px;">';
							
							if(result[j].status=='已交'){
							    list+='<span style="color:green">'+result[j].status+'</span>';
							}else{
								list+='<span style="color:red">'+result[j].status+'</span>';
							}
							
							list+='</div>';
							list+='</div>';
						}
					}
					
					yearmonth = result[i].yearmonth;
				}
				
			}
			
			
		}else{
			
			list+='<div class="am-u-sm-12" style="margin:0px;background: white;padding:10px;text-align:center;">无账单数据...</div>';
		}
		
		$("#bill_list").html(list);
		
	});
	
	
	//添加缴费单
	$("#sub_but").click(function(result){
		
		
		var rTotal=$("#rTotal").val();
		
		var item = new Array();
		
		
		var data="rTotal="+rTotal;
		data="total="+rTotal;
		data+="&name="+$("#name").val();
		data+="&zycode="+$("#zycode").val();
		data+="&compound="+$("#compound").val();
		data+="&payType="+$("#payType").val();
		
		
			
		$("[name='yearmonth']").each(function(){
			//alert(this.id);
		    $("[name='"+$(this).attr('id')+"']").each(function(){
		    	
		    	
		    	var yearmonth=$(this).attr('name');
		    	var name=$(this).find("div[name='name']").text().trim();
		    	var qsaccount=$(this).find("span[name='qsaccount']").text().trim();
		    	item.push({'yearmonth':yearmonth,'name':name,'cost':qsaccount,'num':1,'total':1*qsaccount});
		    	
		    });
		 });
		
		
		
		 data+="&item="+JSON.stringify(item);
		 

		$.post('/webapp/propertyorder/add',data,function(resultdata){
			
			if(resultdata.resultCode == "0"){
				window.location.href = "/webapp/propetry/orderok?orderno=" + resultdata.orderNo;
			}
			
			
		});
		
		
	});
	
	
	
	
	
	
}



function bt1(){
	var status=$("#status").val();
	if(status!='已认证'){
		 $("#textmsg").text('亲，您还未身份认证哦!');
		 $('#modal-alert').modal({
			 relatedTarget: this,
		 });
		 return;
	}
	
	location.href="/propertyfees";
	
	
}

function bt2(){
	var status=$("#status").val();
	if(status!='已认证'){
		 $("#textmsg").text('亲，您还未身份认证哦!');
		 $('#modal-alert').modal({
			 relatedTarget: this,
		 });
		 return;
	}
	
	location.href="/propertybill";
	
	
}


function bt3(){
	var status=$("#status").val();
	if(status!='已认证'){
		 $("#textmsg").text('亲，您还未身份认证哦!');
		 $('#modal-alert').modal({
			 relatedTarget: this,
		 });
		 return;
	}
	
	location.href="/article?type=物业公告";
	
	
}


function bt4(){
	var status=$("#status").val();
	if(status!='已认证'){
		 $("#textmsg").text('亲，您还未身份认证哦!');
		 $('#modal-alert').modal({
			 relatedTarget: this,
		 });
		 return;
	}
	
	location.href="/article?type=维修通知";
	
	
}

function bt5(){
	var status=$("#status").val();
	if(status!='已认证'){
		 $("#textmsg").text('亲，您还未身份认证哦!');
		 $('#modal-alert').modal({
			 relatedTarget: this,
		 });
		 return;
	}
	
	location.href="/article?type=业务指引";
	
	
}

function bt6(){
	var status=$("#status").val();
	if(status!='已认证'){
		 $("#textmsg").text('亲，您还未身份认证哦!');
		 $('#modal-alert').modal({
			 relatedTarget: this,
		 });
		 return;
	}
	
	location.href="/repair";
	
	
}


